
;(function (RCABase) {

    var init_tx = {
        getBurial:function (table_id,url,type,t) {
            console.log("#table_"+table_id)
            console.log(url)
            var columns=[];
            if (type=='dj'){
                if (t==1){
                    columns = [
                        {
                            field: 'no', title: '序号', formatter: function (value, row, index) {
                                //获取每页显示的数量
                                var pageSize = $("#table_"+table_id ).bootstrapTable('getOptions').pageSize;
                                //获取当前是第几页
                                var pageNumber = $("#table_"+table_id).bootstrapTable('getOptions').pageNumber;
                                //返回序号，注意index是从0开始的，所以要加上1
                                return pageSize * (pageNumber - 1) + index + 1;
                            }
                        },
                        {field: 'end_time', title: '定金到期时间'},
                        {field: 'buyer_name', title: '客户名称'},
                        {field: 'buyer_phone', title: '联系方式'},
                        {field: 'cart_type', title: '证件类型'},
                        {field: 'cart_num', title: '身份证号'},
                        {field: 'mw_num', title: '墓位编号'},
                        {field: 'mw_address', title: '具体位置'},
                        {field: 'closing_price', title: '销售价格'},
                        {field: 'deposit_price', title: '已交定金', formatter: function (value, row, index) {
                                var href = '';
                                if (row.status==0){
                                    return '未交定金';
                                } else {
                                    return value;
                                }

                                return value;
                            }},
                        {field: 'add_time', title: '缴费日期'},
                        {field: 'handle_name', title: '经办人'},
                        {
                            field: 'operate',
                            title: '操作',
                            align: 'center',
                            events: "operateEventsDingjin",
                            formatter: function (value, row, index) {
                                var href = '';
                                if (row.status==0){
                                    // href += ' <a href="javascript:"  class="dj_td ">  重置</a>  '
                                    href += ' <a href="javascript:"  class="dj_td">  退定</a>  ';
                                } else {
                                    href += ' <a href="javascript:"  class="dj_td">  退定</a>  ';
                                    href += ' <a href="javascript:" class="jd_wk">完款</a>';
                                    href += ' <a href="javascript:" class="bddj_url">补打</a>';
                                }
                                return href;
                            }
                        }];
                } else if (t==2){
                    columns = [
                        {
                            field: 'no', title: '序号', formatter: function (value, row, index) {
                                //获取每页显示的数量
                                var pageSize = $("#table_"+table_id).bootstrapTable('getOptions').pageSize;
                                //获取当前是第几页
                                var pageNumber = $("#table_"+table_id).bootstrapTable('getOptions').pageNumber;
                                //返回序号，注意index是从0开始的，所以要加上1
                                return pageSize * (pageNumber - 1) + index + 1;
                            }
                        },
                        {field: 'end_time', title: '定金到期时间'},
                        {field: 'buyer_name', title: '客户名称'},
                        {field: 'buyer_phone', title: '联系方式'},
                        {field: 'cart_type', title: '证件类型'},
                        {field: 'cart_num', title: '身份证号'},
                        {field: 'mw_num', title: '墓位编号'},
                        {field: 'mw_address', title: '具体位置'},
                        {field: 'closing_price', title: '销售价格'},
                        {field: 'deposit_price', title: '已交定金'},
                        {field: 'add_time', title: '缴费日期'},
                        {field: 'handle_name', title: '经办人'}
                        ];
                } else if (t==3){
                    columns = [
                        {
                            field: 'no', title: '序号', formatter: function (value, row, index) {
                                //获取每页显示的数量
                                var pageSize = $("#table_"+table_id ).bootstrapTable('getOptions').pageSize;
                                //获取当前是第几页
                                var pageNumber = $("#table_"+table_id).bootstrapTable('getOptions').pageNumber;
                                //返回序号，注意index是从0开始的，所以要加上1
                                return pageSize * (pageNumber - 1) + index + 1;
                            }
                        },
                        {field: 'end_time', title: '定金到期时间'},
                        {field: 'buyer_name', title: '客户名称'},
                        {field: 'buyer_phone', title: '联系方式'},
                        {field: 'cart_type', title: '证件类型'},
                        {field: 'cart_num', title: '身份证号'},
                        {field: 'mw_num', title: '墓位编号'},
                        {field: 'mw_address', title: '具体位置'},
                        {field: 'closing_price', title: '销售价格'},
                        {field: 'deposit_price', title: '已交定金'},
                        {field: 'add_time', title: '缴费日期'},
                        {field: 'handle_name', title: '经办人'}
                        ]

                } else if (t==4){
                    columns = [
                        {
                            field: 'no', title: '序号', formatter: function (value, row, index) {
                                //获取每页显示的数量
                                var pageSize = $("#table_"+table_id ).bootstrapTable('getOptions').pageSize;
                                //获取当前是第几页
                                var pageNumber = $("#table_"+table_id).bootstrapTable('getOptions').pageNumber;
                                //返回序号，注意index是从0开始的，所以要加上1
                                return pageSize * (pageNumber - 1) + index + 1;
                            }
                        },
                        {field: 'end_time', title: '定金到期时间'},
                        {field: 'buyer_name', title: '客户名称'},
                        {field: 'buyer_phone', title: '联系方式'},
                        {field: 'cart_type', title: '证件类型'},
                        {field: 'cart_num', title: '身份证号'},
                        {field: 'mw_num', title: '墓位编号'},
                        {field: 'mw_address', title: '具体位置'},
                        {field: 'closing_price', title: '销售价格'},
                        {field: 'deposit_price', title: '退定金'},
                        {field: 'add_time', title: '退定金日期'},
                        {field: 'handle_name', title: '经办人'},
                        ];
                }

            } else if (type=='lz'){
                columns = [
                    {field: 'buried_time', title: '预约落葬时间'},
                    {field: 'tomb_num', title: '墓位编号'},
                    {field: 'tomb_address', title: '具体位置'},
                    {field: 'dealer_user', title: '办理人'},
                    {field: 'dealer_phone', title: '联系方式'},
                    {field: 'buyer_name', title: '持证人'},
                    {field: 'dead_name', title: '逝者姓名'},
                    {field: 'funeral_type', title: '落葬类别'},
                    {field: 'handle_name', title: '经办人'},
                    {field: 'etiquette_service', title: '礼仪服务'},
                    {field: 'service_status', title: '状态', formatter: function (value, row, index) {
                            if (row.service_status == 3) {
                                return '已落葬'
                            } else {
                                return '未落葬'
                            }
                        }}
                ];
            } else if (type=='jc'){
                columns = [
                    {field: 'deposit_time', title: '预约寄存时间'},
                    {field: 'tomb_num', title: '墓位编号'},
                    {field: 'tomb_address', title: '具体位置'},
                    {field: 'dealer_user', title: '办理人'},
                    {field: 'dealer_sex', title: '性别'},
                    {field: 'dealer_phone', title: '联系方式'},
                    {field: 'buyer_name', title: '持证人'},
                    {field: 'dead_name', title: '逝者姓名'},
                    {field: 'handle_name', title: '经办人'},
                    {field: 'service_status', title: '状态', formatter: function (value, row, index) {
                            if (row.service_status == 3) {
                                return '已完成'
                            } else if (row.service_status == 2) {
                                return '已确认'
                            } else {
                                return '未完成'
                            }
                        }}
                ];
            } else if (type=='jc_out'){
                columns = [
                    {field: 'deposit_time', title: '预约寄出时间'},
                    {field: 'tomb_num', title: '墓位编号'},
                    {field: 'tomb_address', title: '具体位置'},
                    {field: 'dealer_user', title: '办理人'},
                    {field: 'dealer_sex', title: '性别'},
                    {field: 'dealer_phone', title: '联系方式'},
                    {field: 'buyer_name', title: '持证人'},
                    {field: 'dead_name', title: '逝者姓名'},
                    {field: 'handle_name', title: '经办人'},
                    {field: 'service_status', title: '状态', formatter: function (value, row, index) {
                            if (row.service_status == 3) {
                                return '已完成'
                            } else if (row.service_status == 2) {
                                return '已确认'
                            } else {
                                return '未完成'
                            }
                        }}
                ];
            } else if (type=='qm'){
                columns = [
                    {field: 'move_time', title: '预约迁墓时间'},
                    {field: 'tomb_num', title: '墓位编号'},
                    {field: 'tomb_address', title: '具体位置'},
                    {field: 'dealer_user', title: '办理人'},
                    {field: 'buyer_sex', title: '性别'},
                    {field: 'dealer_phone', title: '联系方式'},
                    {field: 'buyer_name', title: '持证人'},
                    {field: 'death_name', title: '迁出的逝者姓名'},
                    {field: 'tombstone_plan', title: '原碑处理方案'},
                    {field: 'handle_name', title: '经办人'},
                    {field: 'service_status', title: '状态', formatter: function (value, row, index) {
                            if (row.service_status == 3) {
                                return '已完成'
                            } else if (row.service_status == 2) {
                                return '已确认'
                            } else {
                                return '未完成'
                            }
                        }}
                ];
            } else if (type=='wb'){
                columns = [
                    {field: 'register_time', title: '登记时间'},
                    {field: 'deliver_time', title: '交付时间'},
                    {field: 'business_num', title: '业务编号'},
                    {field: 'business_type', title: '业务类型'},
                    {field: 'business_content', title: '业务内容'},
                    {field: 'tomb_num', title: '墓位编号'},
                    {field: 'tomb_address', title: '具体位置'},
                    {field: 'handle_name', title: '经办人'},
                    {field: 'service_status', title: '状态', formatter: function (value, row, index) {
                            if (row.service_status == 3) {
                                return '已完成'
                            } else if (row.service_status == 2) {
                                return '已确认'
                            } else if (row.service_status == 4) {
                                return '已上传反馈'
                            } else {
                                return '未完成'
                            }
                        }}
                ];
            } else if (type=='wh'){
                columns = [
                    {field: 'date_time', title: '续费时间'},
                    {field: 'dealer', title: '办理人姓名'},
                    {field: 'sex_name', title: '办理人性别'},
                    {field: 'phone', title: '联系方式'},
                    {field: 'mw_num', title: '墓位编号'},
                    {field: 'mw_address', title: '具体位置'},
                    {field: 'relation', title: '与逝者关系'},
                    {field: 'duration_name', title: '续费时长'},
                    {field: 'handle_name', title: '经办人'},
                    {field: 'service_status', title: '状态', formatter: function (value, row, index) {
                        return '已完成'
                        }}
                ];
            } else if (type=='dd'){
                console.log(t)
                if (t==1) {
                    columns = [
                        {field: 'order_sn', title: '订单ID'},
                        {field: 'customer_name', title: '客户名称'},
                        {field: 'customer_phone', title: '联系电话'},
                        {field: 'tomb_num', title: '墓位编号'},
                        {field: 'tomb_address', title: '具体位置'},
                        {field: 'sell_price', title: '销售价格'},
                        {field: 'sell_time', title: '选位时间'},
                        {field: 'end_time', title: '保留截止时间'},
                        {field: 'user_nickname', title: '导购员'},
                        {
                            field: 'operate',
                            title: '操作',
                            align: 'center',
                            events: "operateEventsDingjin",
                            formatter: function (value, row, index) {
                                var href = '';
                                if (row.order_id!=0){
                                    href += ' <a href="javascript:" class="jd_wk">完款</a>';
                                } else {
                                    href += ' <a href="javascript:"  class="rengou">  认购</a>  '
                                    href += ' <a href="javascript:" class="dd_qx_delete">取消</a>'
                                    href += ' <a href="javascript:" class="dd_hw">换位</a>'
                                }
                                return href;
                            }
                        }];
                }else if (t==2){
                    columns = [
                        {field: 'order_sn', title: '订单ID'},
                        {field: 'customer_name', title: '客户名称'},
                        {field: 'customer_phone', title: '联系电话'},
                        {field: 'tomb_num', title: '墓位编号'},
                        {field: 'tomb_address', title: '具体位置'},
                        {field: 'sell_price', title: '销售价格'},
                        {field: 'sell_time', title: '选位时间'},
                        {field: 'end_time', title: '保留截止时间'},
                        {field: 'user_nickname', title: '导购员'},
                         ];
                } else {
                    columns = [
                        {field: 'order_sn', title: '订单ID'},
                        {field: 'customer_name', title: '客户名称'},
                        {field: 'customer_phone', title: '联系电话'},
                        {field: 'tomb_num', title: '墓位编号'},
                        {field: 'tomb_address', title: '具体位置'},
                        {field: 'sell_price', title: '销售价格'},
                        {field: 'sell_time', title: '选位时间'},
                        {field: 'end_time', title: '保留截止时间'},
                        {field: 'user_nickname', title: '导购员'},
                        {
                            field: 'operate',
                            title: '操作',
                            align: 'center',
                            events: "operateEventsDingjin",
                            formatter: function (value, row, index) {
                                var href = '';
                                // href += ' <a href="javascript:"  class="rengou">  认购</a>  '
                                // href += ' <a href="javascript:" class="jd_wk">取消</a>'
                                // href += ' <a href="javascript:" class="bddj_url">换位</a>'
                                return href;
                            }
                        }];
                }
            }

            $("#table_"+table_id ).bootstrapTable( {
                url: url,
                pageNumber: 1, //初始化加载第一页
                pagination: true,//是否分页
                sidePagination: 'server',//server:服务器端分页|client：前端分页
                pageSize: 10,//单页记录数
                pageList: [ 10, 20,30,50,100],//可选择单页记录数
                showRefresh: false,//刷新按钮
                showColumns: false, //
                columns: columns,
                queryParams: function (params) {
                    //上传服务器的参数
                    var temp = {
                        page: params.offset + 0,// SQL语句起始索引
                        limit: params.limit  // 每页显示数量
                    };
                    return temp;
                },
                formatLoadingMessage: function () {
                    return "数据正在加载中...";
                },
                formatNoMatches: function () {
                    return '无符合条件的记录';
                },
            });
        },
    }

    window.operateEventsDingjin = {
        'click .dj_td': function (e, value, row, index) {
            var url = row.djtx_tk_url;
            openIframeLayer(url,'定金退款',{area: ['700px', '600px'],btn: false,}, '600px', '560px')
        },
        'click .jd_wk': function (e, value, row, index) {
            console.log(row.djtx_wk_url)
            window.location.href = row.djtx_wk_url;
        },
        'click .bddj_url': function (e, value, row, index) {
            $.ajax({
                type: "get", url:row.bddj_url,
                success: function (strHtml) {
                    console.log('打印')
                    var data = strHtml.data;
                    $('#print_html').html(data.html)
                    preViewPrint('服务结算单',1,0)
                }
            })
        },
        'click .rengou': function (e, value, row, index) {
            window.location.href = row.rg_url;
        },
        'click .dd_qx_delete': function (e, value, row, index) {
            window.location.href = row.qx_dele_url;
        },
        'click .dd_hw': function (e, value, row, index) {
            window.location.href = row.hw_url;
        }
    }

    // 查询
    $('#dj_sosuo').bind('click',function(){
        var real_name=$('#buyer_name').val(), real_phone=$('#buyer_phone').val(),
            startTime=$('#startData').val(),　　//获取开始时间戳
            endTime=$('#endData').val();　　　 //获取结束时间戳
        var url = $(this).data('url');
        var tp = $(this).data('type');
        // var tt = $(this).data('tt');
        var table_id = $('#nav_tabs').find('.active').data('table_id');
        var tt = $('#nav_tabs').find('.active').data('t');
        $("#table_"+table_id).bootstrapTable('refresh', {url:url,
            query: {ajax:1,type:tp,t:tt,real_phone:real_phone,real_name:real_name,start_time:startTime,end_time:endTime}});
    });

    var tx_init = function(config) {
        init_tx.getBurial(config.dataId,config.url,config.appKey,1);
    }

    //切换显示
    $(document).on('click','.nav_tabs li',function(){
        var type = $(this).data('type');
        var t = $(this).data('t');
        var url = $(this).data('url');
        var table_id = $(this).data('table_id');

        $(this).addClass('active').siblings().removeClass('active');
        var index = $(".nav_tabs li").index(this);
        console.log(index)
        if (index==0){
            $("#table_"+table_id).bootstrapTable('refresh', {url:url,
                query: {}});
        } else {
            console.log(index)
            init_tx.getBurial(table_id,url,type,t);
            $("#table_"+table_id).bootstrapTable('refresh', {url:url,
                query: {}});
        }
        $('.content_nav').eq(index).removeClass("feature").siblings().addClass("feature");
    });


    RCABase.tx_init = tx_init;
}(RCABase))